@echo off
setlocal
:: Switch codepage to UTF-8 to handle Chinese characters in filenames
chcp 65001 > nul

:: ============================================================================
:: Nuitka Build Script for "亮亮编译命令 生成工具"
:: ============================================================================
::
:: This script compiles the Python project using Nuitka with optimizations
:: to speed up the process and reduce the output size.
::
:: Key Optimizations:
:: 1. --nofollow-import-to=... : Prevents Nuitka from including large,
::    unused PySide6 modules (like WebEngine, 3D, Charts), which is the
::    primary method for speeding up the build.
:: 2. --show-progress / --show-scons : Provides detailed feedback during
::    compilation.
::
:: ============================================================================

:: --- Configuration ---
set VENV_PYTHON=.\.venv\Scripts\python.exe
set MAIN_SCRIPT=main.py
set OUTPUT_DIR=dist\nuitka_output
set OUTPUT_FILENAME="亮亮编译命令生成工具"
set ICON_FILE=logo.ico
set NUM_JOBS=%NUMBER_OF_PROCESSORS%

echo ==================================================
echo      Starting Nuitka Compilation
echo ==================================================
echo.
echo Main Script:      %MAIN_SCRIPT%
echo Output Directory: %OUTPUT_DIR%
echo Output Filename:  %OUTPUT_FILENAME%
echo.

:: --- Run Nuitka Compilation ---
%VENV_PYTHON% -m nuitka ^
    --output-dir=%OUTPUT_DIR% ^
    --output-filename=%OUTPUT_FILENAME% ^
    %MAIN_SCRIPT% ^
    --standalone ^
    --windows-console-mode=disable ^
    --mingw64 ^
    --lto=yes ^
    --enable-plugin=pyside6 ^
    --windows-icon-from-ico=%ICON_FILE% ^
    --jobs=%NUM_JOBS% ^
    --include-data-file=STXingkai.ttf=STXingkai.ttf ^
    --include-data-file=logo.ico=logo.ico ^
    --nofollow-import-to=PySide6.QtTest ^
    --nofollow-import-to=PySide6.QtQuick ^
    --nofollow-import-to=PySide6.QtQml ^
    --nofollow-import-to=PySide6.QtWebEngineWidgets ^
    --nofollow-import-to=PySide6.QtWebEngineCore ^
    --nofollow-import-to=PySide6.Qt3DCore ^
    --nofollow-import-to=PySide6.Qt3DRender ^
    --nofollow-import-to=PySide6.Qt3DInput ^
    --nofollow-import-to=PySide6.Qt3DLogic ^
    --nofollow-import-to=PySide6.Qt3DExtras ^
    --nofollow-import-to=PySide6.QtCharts ^
    --nofollow-import-to=PySide6.QtDataVisualization ^
    --nofollow-import-to=PySide6.QtNetworkAuth ^
    --show-progress ^
    --show-scons

echo.
echo ==================================================
echo      Compilation Finished
echo ==================================================
echo.
echo Your executable can be found in the '%OUTPUT_DIR%' directory.
echo.
pause